$(function() {
    $("#hello").click(function (){
        let serverUrl = "http://localhost:8082/hello";
        $.ajax({
            headers: {
                "X-XSRF-TOKEN": $.cookie("XSRF-TOKEN")
            },
            data:"",
            type:"GET",
            dataType:"json",
            async:true,
            crossDomain: true,
            contentType: "application/json",
            url:serverUrl,
            success:function(data){
                if(data.code == "10000"){
                    window.location.href = "login.html";
                }else{
                    $("#helloValue").val(data.data);
                }
            }
        });
    });

    $("#logout").click(function (){
        let serverUrl = "http://localhost:8082/logout";
        $.ajax({
            headers: {
                "X-XSRF-TOKEN": $.cookie("XSRF-TOKEN")
            },
            data:"",
            type:"POST",
            dataType:"json",
            async:true,
            contentType: "application/json",
            url:serverUrl,
            success:function(data){
                if(data.code == "1220"){ // 处理退出登录
                    window.location.href = "hello.html";
                }
                else{
                    $("#helloValue").val(data.message);
                }
            }
        });
    });

    $("#student").click(function (){
        let serverUrl = "http://localhost:8082/student";
        $.ajax({
            headers: {
                "X-XSRF-TOKEN": $.cookie("XSRF-TOKEN")
            },
            data:"",
            type:"POST",
            dataType:"json",
            async:true,
            contentType: "application/json",
            url:serverUrl,
            success:function(data){
                if(data.code == "10000"){
                    window.location.href = "login.html";
                }else{
                    $("#student_name").val(data.data.name);
                    $("#student_school").val(data.data.school);
                }
            }
        });
    });
});